package zcxn.microService.daoUtil;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import zcxn.microService.daoUtil.*;

public class DaoUtil {
	private static SqlSessionFactory sessionFactory = null;
	private static DaoUtil daoUtil = new DaoUtil();
	private DaoUtil()
	{
		try {
			InputStream inputStream=Resources.getResourceAsStream("mybatis-config.xml");
			sessionFactory=new SqlSessionFactoryBuilder().build(inputStream);
		
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public static SqlSession getSqlSession() {
		return DaoUtil.sessionFactory.openSession(true);
	}
	public static void close(SqlSession session) {
		if(session!=null) {
			session.close();
		}
	}
}
